<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-transform" />
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="format-detection" content="telephone=no,email=no,adress=no">
  <!-- Color theme for statusbar -->
  <meta name="theme-color" content="#000000" />
  <!-- 强制页面在当前窗口以独立页面显示,防止别人在框架里调用页面 -->
  <meta http-equiv="window-target" content="_top" />
  
  
  <title>JavaSE_01 | 金旭的个人博客</title>
  <meta name="description" content="JDK、JRE、JVM三者的关系JDK(Java Development Kit)JDK是整个JAVA的核心，包括了Java运行环境（Java Runtime Envirnment），一堆Java工具（javac&#x2F;java&#x2F;jdb等）和Java基础的类库（即Java API 包括rt.jar）。JDK是java开发工具包，基本上每个学java的人都会先在机器上装一个JDK，那他都包含哪几部分呢？在">
<meta property="og:type" content="article">
<meta property="og:title" content="JavaSE_01">
<meta property="og:url" content="http://sunjinxu99.gitee.io/blog/2020/03/31/javaSE_01/index.html">
<meta property="og:site_name" content="金旭的个人博客">
<meta property="og:description" content="JDK、JRE、JVM三者的关系JDK(Java Development Kit)JDK是整个JAVA的核心，包括了Java运行环境（Java Runtime Envirnment），一堆Java工具（javac&#x2F;java&#x2F;jdb等）和Java基础的类库（即Java API 包括rt.jar）。JDK是java开发工具包，基本上每个学java的人都会先在机器上装一个JDK，那他都包含哪几部分呢？在">
<meta property="og:image" content="https://gitee.com/sunjinxu99/image/raw/master/img/20200331162355.png">
<meta property="og:image" content="https://gitee.com/sunjinxu99/image/raw/master/img/20200402084518.png">
<meta property="og:image" content="https://gitee.com/sunjinxu99/image/raw/master/img/20200402084523.png">
<meta property="og:image" content="https://gitee.com/sunjinxu99/image/raw/master/img/20200402084520.png">
<meta property="article:published_time" content="2020-03-31T02:07:40.420Z">
<meta property="article:modified_time" content="2020-04-12T03:20:22.462Z">
<meta property="article:author" content="金旭">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/sunjinxu99/image/raw/master/img/20200331162355.png">
  <!-- Canonical links -->
  <link rel="canonical" href="http://sunjinxu99.gitee.io/blog/2020/03/31/javaSE_01/index.html">
  
    <link rel="alternate" href="/atom.xml" title="金旭的个人博客" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png" type="image/x-icon">
  
  
<link rel="stylesheet" href="/blog/css/style.css">

  
  
  
  
<meta name="generator" content="Hexo 4.2.0"></head>


<body class="main-center theme-blue# 主题颜色 theme-black theme-blue theme-green theme-purple" itemscope itemtype="http://schema.org/WebPage">
  <header class="header" itemscope itemtype="http://schema.org/WPHeader">
  <div class="slimContent">
    <div class="navbar-header">
      
      
      <div class="profile-block text-center">
        <a id="avatar" href="" target="_blank">
          <img class="img-circle img-rotate" src="/blog/images/avatar.png" width="200" height="200">
        </a>
        <h2 id="name" class="hidden-xs hidden-sm">小马</h2>
        <h3 id="title" class="hidden-xs hidden-sm hidden-md"></h3>
        <small id="location" class="text-muted hidden-xs hidden-sm"><i class="icon icon-map-marker"></i> </small>
      </div>
      
      <div class="search" id="search-form-wrap">

    <form class="search-form sidebar-form">
        <div class="input-group">
            <input type="text" class="search-form-input form-control" placeholder="Search" />
            <span class="input-group-btn">
                <button type="submit" class="search-form-submit btn btn-flat" onclick="return false;"><i class="icon icon-search"></i></button>
            </span>
        </div>
    </form>
    <div class="ins-search">
  <div class="ins-search-mask"></div>
  <div class="ins-search-container">
    <div class="ins-input-wrapper">
      <input type="text" class="ins-search-input" placeholder="Type something..." x-webkit-speech />
      <button type="button" class="close ins-close ins-selectable" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
    </div>
    <div class="ins-section-wrapper">
      <div class="ins-section-container"></div>
    </div>
  </div>
</div>


</div>
      <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#main-navbar" aria-controls="main-navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>
    <nav id="main-navbar" class="collapse navbar-collapse" itemscope itemtype="http://schema.org/SiteNavigationElement" role="navigation">
      <ul class="nav navbar-nav main-nav ">
        
        
        <li class="menu-item menu-item-home">
          <a href="/blog/.">
            
            <i class="icon icon-home-fill"></i>
            
            <span class="menu-title">Home</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives">
            
            <i class="icon icon-archives-fill"></i>
            
            <span class="menu-title">Archives</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories">
            
            <i class="icon icon-folder"></i>
            
            <span class="menu-title">Categories</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags">
            
            <i class="icon icon-tags"></i>
            
            <span class="menu-title">Tags</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-about">
          <a href="/blog/about">
            
            <i class="icon icon-cup-fill"></i>
            
            <span class="menu-title">About</span>
          </a>
        </li>
        
      </ul>
      
    </nav>
  </div>
</header>

  
    <aside class="sidebar" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    
      <div class="widget">
    <h3 class="widget-title">Board</h3>
    <div class="widget-body">
        <div id="board">
            <div class="content">
                <p>朝闻道夕死可矣</p>
            </div>
        </div>
    </div>
</div>

    
      
  <div class="widget">
    <h3 class="widget-title">Categories</h3>
    <div class="widget-body">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/blog/categories/JavaSE/">JavaSE</a><span class="category-list-count">7</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/LeetCode/">LeetCode</a><span class="category-list-count">3</span><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/blog/categories/LeetCode/%E7%AE%97%E6%B3%95/">算法</a><span class="category-list-count">3</span></li></ul></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E6%9D%82%E8%AE%B0/">杂记</a><span class="category-list-count">1</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget-body tagcloud">
      <a href="/blog/tags/IO%E6%B5%81/" style="font-size: 13px;">IO流</a> <a href="/blog/tags/OSI%E5%8F%82%E8%80%83%E6%A8%A1%E5%9E%8B/" style="font-size: 13px;">OSI参考模型</a> <a href="/blog/tags/TCP-IP%E5%8F%82%E8%80%83%E6%A8%A1%E5%9E%8B/" style="font-size: 13px;">TCP/IP参考模型</a> <a href="/blog/tags/ftp%E5%8D%8F%E8%AE%AE/" style="font-size: 13px;">ftp协议</a> <a href="/blog/tags/http/" style="font-size: 13px;">http</a> <a href="/blog/tags/leetcode/" style="font-size: 13px;">leetcode</a> <a href="/blog/tags/%E4%BA%8C%E5%88%86%E6%95%B0%E7%BB%84/" style="font-size: 13px;">二分数组</a> <a href="/blog/tags/%E4%BA%8C%E5%8F%89%E6%A0%91/" style="font-size: 13px;">二叉树</a> <a href="/blog/tags/%E5%85%A8%E6%8E%92%E5%88%97/" style="font-size: 13px;">全排列</a> <a href="/blog/tags/%E5%8F%8C%E6%8C%87%E9%92%88/" style="font-size: 13.33px;">双指针</a> <a href="/blog/tags/%E5%8F%8D%E5%B0%84/" style="font-size: 13px;">反射</a> <a href="/blog/tags/%E5%93%88%E5%B8%8C%E8%A1%A8/" style="font-size: 13.67px;">哈希表</a> <a href="/blog/tags/%E5%9B%9E%E6%BA%AF%E6%B3%95/" style="font-size: 13px;">回溯法</a> <a href="/blog/tags/%E5%A4%9A%E7%BA%BF%E7%A8%8B/" style="font-size: 13px;">多线程</a> <a href="/blog/tags/%E5%AD%97%E7%AC%A6%E4%B8%B2/" style="font-size: 13px;">字符串</a> <a href="/blog/tags/%E6%8E%92%E5%BA%8F/" style="font-size: 13.33px;">排序</a> <a href="/blog/tags/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/" style="font-size: 14px;">数据结构</a> <a href="/blog/tags/%E6%9D%82%E8%AE%B0/" style="font-size: 13px;">杂记</a> <a href="/blog/tags/%E6%A0%88/" style="font-size: 13px;">栈</a> <a href="/blog/tags/%E6%B3%9B%E5%9E%8B/" style="font-size: 13px;">泛型</a> <a href="/blog/tags/%E7%AE%97%E6%B3%95/" style="font-size: 13.33px;">算法</a> <a href="/blog/tags/%E8%8F%B2%E6%B3%A2%E9%82%A3%E5%88%87%E6%95%B0%E5%88%97/" style="font-size: 13.33px;">菲波那切数列</a> <a href="/blog/tags/%E9%80%92%E5%BD%92/" style="font-size: 13px;">递归</a> <a href="/blog/tags/%E9%93%BE%E8%A1%A8/" style="font-size: 13.33px;">链表</a> <a href="/blog/tags/%E9%98%9F%E5%88%97/" style="font-size: 13px;">队列</a> <a href="/blog/tags/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1/" style="font-size: 13px;">面向对象</a>
    </div>
  </div>

    
      
  <div class="widget">
    <h3 class="widget-title">Archive</h3>
    <div class="widget-body">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2021/07/">July 2021</a><span class="archive-list-count">9</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2020/07/">July 2020</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2020/05/">May 2020</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2020/04/">April 2020</a><span class="archive-list-count">8</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2020/03/">March 2020</a><span class="archive-list-count">10</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget-body">
      <ul class="recent-post-list list-unstyled no-thumbnail">
        
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                
              </p>
              <p class="item-title">
                <a href="/blog/2021/07/14/%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E9%95%9C%E5%83%8F/" class="title">二叉树的镜像</a>
              </p>
              <p class="item-date">
                <time datetime="2021-07-14T12:34:40.165Z" itemprop="datePublished">2021-07-14</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                
              </p>
              <p class="item-title">
                <a href="/blog/2021/07/14/%E5%90%88%E5%B9%B6%E4%B8%A4%E4%B8%AA%E6%8E%92%E5%BA%8F%E7%9A%84%E9%93%BE%E8%A1%A8/" class="title">合并两个排序的链表</a>
              </p>
              <p class="item-date">
                <time datetime="2021-07-14T09:26:07.612Z" itemprop="datePublished">2021-07-14</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                
              </p>
              <p class="item-title">
                <a href="/blog/2021/07/14/%E4%BB%8E%E5%B0%BE%E5%88%B0%E5%A4%B4%E6%89%93%E5%8D%B0%E9%93%BE%E8%A1%A8/" class="title">从尾到头打印链表</a>
              </p>
              <p class="item-date">
                <time datetime="2021-07-14T08:02:42.111Z" itemprop="datePublished">2021-07-14</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                
              </p>
              <p class="item-title">
                <a href="/blog/2021/07/14/%E6%9B%BF%E6%8D%A2%E7%A9%BA%E6%A0%BC/" class="title">替换空格</a>
              </p>
              <p class="item-date">
                <time datetime="2021-07-14T06:28:22.026Z" itemprop="datePublished">2021-07-14</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                
              </p>
              <p class="item-title">
                <a href="/blog/2021/07/14/%E6%97%8B%E8%BD%AC%E6%95%B0%E7%BB%84%E7%9A%84%E6%9C%80%E5%B0%8F%E6%95%B0%E5%AD%97/" class="title">旋转数组的最小数字</a>
              </p>
              <p class="item-date">
                <time datetime="2021-07-14T06:12:09.184Z" itemprop="datePublished">2021-07-14</time>
              </p>
            </div>
          </li>
          
      </ul>
    </div>
  </div>
  

    
  </div>
</aside>

  
  
<main class="main" role="main">
  <div class="content">
  <article id="post-javaSE_01" class="article article-type-post" itemscope itemtype="http://schema.org/BlogPosting">
    
    <div class="article-header">
      
        
  
    <h1 class="article-title" itemprop="name">
      JavaSE_01
    </h1>
  

      
      <div class="article-meta">
        <span class="article-date">
    <i class="icon icon-calendar-check"></i>
	<a href="/blog/2020/03/31/javaSE_01/" class="article-date">
	  <time datetime="2020-03-31T02:07:40.420Z" itemprop="datePublished">2020-03-31</time>
	</a>
</span>
        
  <span class="article-category">
    <i class="icon icon-folder"></i>
    <a class="article-category-link" href="/blog/categories/JavaSE/">JavaSE</a>
  </span>

        

        

        <span class="post-comment"><i class="icon icon-comment"></i> <a href="/blog/2020/03/31/javaSE_01/#comments" class="article-comment-link">Comments</a></span>
        
      </div>
    </div>
    <div class="article-entry marked-body" itemprop="articleBody">
      
        <h3 id="JDK、JRE、JVM三者的关系"><a href="#JDK、JRE、JVM三者的关系" class="headerlink" title="JDK、JRE、JVM三者的关系"></a>JDK、JRE、JVM三者的关系</h3><h4 id="JDK-Java-Development-Kit"><a href="#JDK-Java-Development-Kit" class="headerlink" title="JDK(Java Development Kit)"></a>JDK(Java Development Kit)</h4><p>JDK是整个JAVA的核心，包括了Java运行环境（Java Runtime Envirnment），一堆Java工具（javac/java/jdb等）和Java基础的类库（即Java API 包括rt.jar）。JDK是java开发工具包，基本上每个学java的人都会先在机器上装一个JDK，那他都包含哪几部分呢？在目录下面有 六个文件夹、一个src类库源码压缩包、和其他几个声明文件。其中，真正在运行java时起作用的 是以下四个文件夹：bin、include、lib、jre。有这样一个关系，JDK包含JRE，而JRE包含JVM。</p>
<h4 id="JRE（Java-RuntimeEnvironment"><a href="#JRE（Java-RuntimeEnvironment" class="headerlink" title="JRE（Java RuntimeEnvironment)"></a>JRE（Java RuntimeEnvironment)</h4><p>包含JVM及Java核心类库。JRE是Java运行环境，并不是一个开发环境，所以没有包含任何开发工具（如编译器和调试器）JRE是指java运行环境。光有JVM还不能执行class，因为在解释class的时候JVM需要调用解释所需要的类库lib。jre里有运行.class的java.exe）<br>JRE（Java Runtime Environment）是运行Java程序必不可少的（除非用其他一些编译环境编译成.exe可执行文件），JRE的地位就象一台PC机一样，我们写好的Win64应用程序需要操作系统帮我们运行，同样的，我们编写的Java程序也必须要JRE才能运行。</p>
<h4 id="JVM（Java-Virtual-Machine"><a href="#JVM（Java-Virtual-Machine" class="headerlink" title="JVM（Java Virtual Machine)"></a>JVM（Java Virtual Machine)</h4><p>即java虚拟机, java运行时的环境，JVM是一种用于计算设备的规范，它是一个虚构出来的计算机，是通过在实际的计算机上仿真模拟各种计算机功能来实现的。针对java用户，也就是拥有可运行的.class文件包（jar或者war）的用户。里面主要包含了jvm和java运行时基本类库（rt.jar，rt.jar可以简单粗暴地理解为：它就是java源码编译成的jar包。Java虚拟机在执行字节码时，把字节码解释成具体平台上的机器指令执行。这就是Java的能够“一次编译，到处运行”的原因。</p>
<hr>
<h3 id="标识符的命名规则"><a href="#标识符的命名规则" class="headerlink" title="标识符的命名规则"></a>标识符的命名规则</h3><p>定义类、方法、变量等用到的名称称为标识符。</p>
<h4 id="组成元素："><a href="#组成元素：" class="headerlink" title="组成元素："></a>组成元素：</h4><ul>
<li>英文字符：A-Z a-z</li>
<li>数字：0-9</li>
<li>符号：_和$<h4 id="规则"><a href="#规则" class="headerlink" title="规则"></a>规则</h4></li>
<li>不能以数字开头</li>
<li>不可以使用关键字</li>
<li>严格区分大小写，尽量做到见名知意<h3 id="标识符命名规范"><a href="#标识符命名规范" class="headerlink" title="标识符命名规范"></a>标识符命名规范</h3></li>
<li>包名：xxyyzz</li>
<li>类、接口：XxxYyyZzz</li>
<li>变量、方法：xxYyZz</li>
<li>常量：XX_YY_ZZ</li>
</ul>
<hr>
<h3 id="java基本的数据类型"><a href="#java基本的数据类型" class="headerlink" title="java基本的数据类型"></a>java基本的数据类型</h3><ul>
<li>四种整数类型（byte、short、int、long）</li>
<li>两种浮点数（float、double）</li>
<li>一种字符类型（char）</li>
<li>一种布尔型（boolean）</li>
</ul>
<p><img src="https://gitee.com/sunjinxu99/image/raw/master/img/20200331162355.png" alt=""></p>
<h3 id="类型转化规则"><a href="#类型转化规则" class="headerlink" title="类型转化规则"></a>类型转化规则</h3><ul>
<li>出布尔型例外的其他七种类型都可以相互转换</li>
<li>小容量向大容量类型转换，称为自动转换</li>
<li>大容量向小容量转换，称为强制转换。需要加强制转换符，但可能会损失精度</li>
<li>当整数字面值没有超出 byte、short、char的取值范围，可以直接赋值给byte、short、char类型的变量</li>
<li>byte、short、char做混合运算的时候，先自行转换成int类型再做运算。</li>
<li>多种数据类型混合运算，先转换成容量最大那种类型再做运算。<h4 id="容量大小顺序"><a href="#容量大小顺序" class="headerlink" title="容量大小顺序"></a>容量大小顺序</h4>$byte&lt;short=char&lt;int&lt;long&lt;float&lt;double</li>
<li>任何浮点类型都比整数类型容量大</li>
<li>char、short可表示种类数量相同，但是char可以取更大的正整数</li>
</ul>
<hr>
<h3 id="amp-“和”-amp-amp-“的异同"><a href="#amp-“和”-amp-amp-“的异同" class="headerlink" title="&amp;“和”&amp;&amp;“的异同"></a>&amp;“和”&amp;&amp;“的异同</h3><ul>
<li>普通与：所有判断条件都要判断</li>
<li>短路与：如果前面的条件返回了false，则后面的条件不再判断，最终返回false<h3 id="”-“和”-“的异同"><a href="#”-“和”-“的异同" class="headerlink" title="”|“和”||“的异同"></a>”|“和”||“的异同</h3></li>
<li>普通与：所有判断条件都要判断</li>
<li>短路与：如果前面的条件返回了true，则后面的条件不再判断，最终返回true</li>
</ul>
<hr>
<h3 id="判断输出（44"><a href="#判断输出（44" class="headerlink" title="判断输出（44)"></a>判断输出（44)</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">OperatorTest</span></span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">boolean</span> x = <span class="keyword">true</span>;</span><br><span class="line">        <span class="keyword">boolean</span> y = <span class="keyword">false</span>;</span><br><span class="line">        <span class="keyword">short</span> z = <span class="number">40</span>;</span><br><span class="line">        <span class="keyword">if</span> ((z++ == <span class="number">40</span>) &amp;&amp; (y = <span class="keyword">true</span>))&#123;</span><br><span class="line">            z++;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> ((x = <span class="keyword">false</span>) || (++z == <span class="number">43</span>))&#123;</span><br><span class="line">            z++;</span><br><span class="line">        &#125;</span><br><span class="line">        System.out.println(<span class="string">"z="</span> + z);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<hr>
<p>定义三个int型变量并赋值，并找出最大值</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">int</span> num1 = <span class="number">10</span>, num2=<span class="number">20</span>, num3=-<span class="number">21</span>;</span><br><span class="line"><span class="keyword">int</span> max;</span><br><span class="line"><span class="keyword">if</span> (num1 &gt;= num2) &amp;&amp; (num1 &gt;= num3)&#123;</span><br><span class="line">max = num1;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">else</span> <span class="keyword">if</span>(num2 &gt;= num1) &amp;&amp; (num2 &gt;= num3)&#123;</span><br><span class="line">    max = num2;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">else</span>&#123;</span><br><span class="line">    max = num3;</span><br><span class="line">&#125;</span><br><span class="line">system.out.print(<span class="string">"max num is"</span> + max)</span><br></pre></td></tr></table></figure>
<hr>
<h3 id="声明两个double变量并赋值，判断第一个数大于10-0，且第二个数小于20-0，打印两数至和，否则打印两数的乘积"><a href="#声明两个double变量并赋值，判断第一个数大于10-0，且第二个数小于20-0，打印两数至和，否则打印两数的乘积" class="headerlink" title="声明两个double变量并赋值，判断第一个数大于10.0，且第二个数小于20.0，打印两数至和，否则打印两数的乘积"></a>声明两个double变量并赋值，判断第一个数大于10.0，且第二个数小于20.0，打印两数至和，否则打印两数的乘积</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">double</span> num1 = <span class="number">12.3</span>;</span><br><span class="line"><span class="keyword">double</span> num2 = <span class="number">32.1</span>;</span><br><span class="line"><span class="keyword">if</span>((num1 &gt;<span class="number">10</span> &amp;&amp; num2 &lt; <span class="number">20</span>)&#123;</span><br><span class="line">    system.out.println(num1 + num2);</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">else</span>&#123;</span><br><span class="line">    system.out.println(num1 * num2);</span><br><span class="line">&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="变换两个变量值"><a href="#变换两个变量值" class="headerlink" title="变换两个变量值"></a>变换两个变量值</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">string s1 = <span class="string">'bejing'</span>;</span><br><span class="line">string s2 = <span class="string">'nanjing'</span>;</span><br><span class="line">string temp = s1;</span><br><span class="line">s1 = s2;</span><br><span class="line">s2 = temp;</span><br></pre></td></tr></table></figure>
<hr>
<h3 id="switch后面使用的表达式可以使那些类型？"><a href="#switch后面使用的表达式可以使那些类型？" class="headerlink" title="switch后面使用的表达式可以使那些类型？"></a>switch后面使用的表达式可以使那些类型？</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">      <span class="keyword">switch</span>(变量)&#123;</span><br><span class="line">            <span class="keyword">case</span> 值<span class="number">1</span>：</span><br><span class="line">                功能语句<span class="number">1</span>；</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            <span class="keyword">case</span> 值<span class="number">2</span>：</span><br><span class="line">                功能语句<span class="number">2</span>；</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            <span class="keyword">case</span> 值<span class="number">3</span>：</span><br><span class="line">                功能语句<span class="number">3</span>；</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            <span class="keyword">default</span>:</span><br><span class="line">                功能语句d</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">        &#125;</span><br></pre></td></tr></table></figure>
<p>byte、short、char、int、枚举类型变量、string类型(如VIP、段位、星期、月份等)</p>
<hr>
<h3 id="使用switch改写if语句"><a href="#使用switch改写if语句" class="headerlink" title="使用switch改写if语句"></a>使用switch改写if语句</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">int</span> a = <span class="number">3</span>;</span><br><span class="line"><span class="keyword">int</span> x = <span class="number">100</span>;</span><br><span class="line"><span class="keyword">if</span>(a==<span class="number">1</span>)&#123;</span><br><span class="line">    x+=<span class="number">5</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">else</span> <span class="keyword">if</span>(a==<span class="number">2</span>)&#123;</span><br><span class="line">    x+=<span class="number">10</span>;</span><br><span class="line">&#125; </span><br><span class="line"><span class="keyword">else</span> <span class="keyword">if</span>(a==<span class="number">3</span>)&#123;</span><br><span class="line">    x+=<span class="number">16</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">else</span>&#123;</span><br><span class="line">    x+=<span class="number">20</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">int</span> a = <span class="number">3</span>;</span><br><span class="line"><span class="keyword">int</span> x = <span class="number">100</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">switch</span>(a)&#123;</span><br><span class="line">    <span class="keyword">case</span> <span class="number">1</span>:</span><br><span class="line">        x+=<span class="number">5</span>;</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">    <span class="keyword">case</span> <span class="number">2</span>:</span><br><span class="line">        x+=<span class="number">10</span>;</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">    <span class="keyword">case</span> <span class="number">3</span>:</span><br><span class="line">        x+=<span class="number">16</span>;</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">    <span class="keyword">default</span>:</span><br><span class="line">        x+=<span class="number">20</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<hr>
<h3 id="三元运算符、if-else和switch的不同"><a href="#三元运算符、if-else和switch的不同" class="headerlink" title="三元运算符、if-else和switch的不同"></a>三元运算符、if-else和switch的不同</h3><p>三元运算符的格式[条件语句]？[表达式一]:[表达式二]</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">int</span> a = <span class="number">1</span>;</span><br><span class="line"><span class="keyword">int</span> b = <span class="number">2</span>;</span><br><span class="line"><span class="keyword">int</span> c=a&gt;b?<span class="number">1</span>:<span class="number">0</span></span><br></pre></td></tr></table></figure>
<p>三元运算符合switch都可以改写成if语句，但是三元运算符和switch效率比if语句高。switch的类型有限制，三元运算只能有两个表达式。</p>
<hr>
<p>从控制台获取输入</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.Scanner;</span><br><span class="line"> </span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">intPut</span> </span>&#123;</span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">		<span class="comment">//创建Scanner对象，接受从控制台输入</span></span><br><span class="line">		Scanner input=<span class="keyword">new</span> Scanner(System.in);</span><br><span class="line">		<span class="comment">//接受String类型</span></span><br><span class="line">		String str = input.next();</span><br><span class="line">        <span class="comment">//接收int类型</span></span><br><span class="line">        <span class="keyword">int</span> num = intput.nextint();</span><br><span class="line">		<span class="comment">//输出结果</span></span><br><span class="line">		System.out.println(str);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<hr>
<h3 id="for-循环遍历100以内的奇数并打印他们的和"><a href="#for-循环遍历100以内的奇数并打印他们的和" class="headerlink" title="for 循环遍历100以内的奇数并打印他们的和"></a>for 循环遍历100以内的奇数并打印他们的和</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">int</span>  sum = <span class="number">0</span>;</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=<span class="number">100</span>;i++)&#123;</span><br><span class="line">    <span class="keyword">if</span>(i%<span class="number">2</span> != <span class="number">0</span>)&#123;</span><br><span class="line">        sum+=i;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">System.out.println(sum);</span><br></pre></td></tr></table></figure>
<hr>
<h3 id="continue和break"><a href="#continue和break" class="headerlink" title="continue和break"></a>continue和break</h3><ul>
<li>break：用break语句可以使流程跳出switch循环，或者结束本层循环</li>
<li>continue：循环语句里有此语句时，程序运行到此语句时，不在执行循环体里continue后面的语句而是跳到下一个循环入口处执行下一个循环。<br><img src="https://gitee.com/sunjinxu99/image/raw/master/img/20200402084518.png" alt=""><br><img src="https://gitee.com/sunjinxu99/image/raw/master/img/20200402084523.png" alt=""><br><img src="https://gitee.com/sunjinxu99/image/raw/master/img/20200402084520.png" alt=""></li>
</ul>
<h3 id="如果一个数恰好等于它的因子之和，这个数就是完数，找出1000以内的完数"><a href="#如果一个数恰好等于它的因子之和，这个数就是完数，找出1000以内的完数" class="headerlink" title="如果一个数恰好等于它的因子之和，这个数就是完数，找出1000以内的完数"></a>如果一个数恰好等于它的因子之和，这个数就是完数，找出1000以内的完数</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">1</span>;i&lt;=<span class="number">1000</span>;i++)&#123;</span><br><span class="line">    <span class="keyword">int</span> sum = <span class="number">0</span>;</span><br><span class="line">    <span class="keyword">for</span>(j = <span class="number">1</span>;j &lt;= i/<span class="number">2</span>+<span class="number">1</span>;j++)&#123;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span>(i % j == <span class="number">0</span>)&#123;</span><br><span class="line">            sum+=j;</span><br><span class="line">        &#125;</span><br><span class="line">    <span class="keyword">if</span>(i == sum)&#123;</span><br><span class="line">        System.out.println(i);</span><br><span class="line">    &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<hr>

      
    </div>
    <div class="article-footer">
      <blockquote class="mt-2x">
  <ul class="post-copyright list-unstyled">
    
    <li class="post-copyright-link hidden-xs">
      <strong>本文链接：</strong>
      <a href="http://sunjinxu99.gitee.io/blog/2020/03/31/javaSE_01/" title="JavaSE_01" target="_blank" rel="external">http://sunjinxu99.gitee.io/blog/2020/03/31/javaSE_01/</a>
    </li>
    
    <li class="post-copyright-license">
      <strong>版权声明： </strong> 本博客所有文章除特别声明外，均采用 <a href="http://creativecommons.org/licenses/by/4.0/deed.zh" target="_blank" rel="external">CC BY 4.0 CN协议</a> 许可协议。转载请注明出处！
    </li>
  </ul>
</blockquote>


<div class="panel panel-default panel-badger">
  <div class="panel-body">
    <figure class="media">
      <div class="media-left">
        <a href="" target="_blank" class="img-burn thumb-sm visible-lg">
          <img src="/blog/images/avatar.png" class="img-rounded w-full" alt="">
        </a>
      </div>
      <div class="media-body">
        <h3 class="media-heading"><a href="" target="_blank"><span class="text-dark">小马</span><small class="ml-1x"></small></a></h3>
        <div></div>
      </div>
    </figure>
  </div>
</div>


    </div>
  </article>
  
    
  <section id="comments">
  	
      <div id="vcomments"></div>
    
  </section>


  
</div>

  <nav class="bar bar-footer clearfix" data-stick-bottom>
  <div class="bar-inner">
  
  <ul class="pager pull-left">
    
    <li class="prev">
      <a href="/blog/2020/04/02/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E4%B9%8B%E4%B8%80/" title="面向对象之一"><i class="icon icon-angle-left" aria-hidden="true"></i><span>&nbsp;&nbsp;Newer</span></a>
    </li>
    
    
    <li class="next">
      <a href="/blog/2020/03/26/%E6%8E%92%E5%BA%8F/" title="排序算法"><span>Older&nbsp;&nbsp;</span><i class="icon icon-angle-right" aria-hidden="true"></i></a>
    </li>
    
    
  </ul>
  
  
  
  <div class="bar-right">
    
  </div>
  </div>
</nav>
  


</main>

  <footer class="footer" itemscope itemtype="http://schema.org/WPFooter">
	
    <div class="copyright">
    	
        <div class="publishby">
        	Theme by <a href="https://github.com/cofess" target="_blank"> cofess </a>base on <a href="https://github.com/cofess/hexo-theme-pure" target="_blank">pure</a>.
        </div>
    </div>
</footer>
  <script src="//cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<script>
window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')
</script>

<script src="/blog/js/plugin.min.js"></script>


<script src="/blog/js/application.js"></script>


    <script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: 'Posts',
            PAGES: 'Pages',
            CATEGORIES: 'Categories',
            TAGS: 'Tags',
            UNTITLED: '(Untitled)',
        },
        ROOT_URL: '/blog/',
        CONTENT_URL: '/blog/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>

<script src="/blog/js/insight.js"></script>






   




   
    
  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/valine"></script>
  <script type="text/javascript">
  var GUEST = ['nick', 'mail', 'link'];
  var meta = 'nick,mail,link';
  meta = meta.split(',').filter(function(item) {
    return GUEST.indexOf(item) > -1;
  });
  new Valine({
    el: '#vcomments',
    verify: false,
    notify: false,
    appId: '',
    appKey: '',
    placeholder: 'Just go go',
    avatar: 'mm',
    meta: meta,
    pageSize: '10' || 10,
    visitor: false
  });
  </script>

     







</body>
</html>